<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends T3WD_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */



	public function Home()
	{
		 parent::__construct();
		 $this->_only_authorized_personnel();	
		 $this->load->helper('form');
		 
		 $name_module = 'home';
		if($name_module!==$this->session->userdata('name_module')){
			$this->session->set_userdata('name_module', $name_module);
			$this->session->set_userdata('userSort', 0);
			$this->session->set_userdata('userDirection', 0);
			$this->session->set_userdata('userCount', 0);	
			$this->session->set_userdata('search', '');

		}
		
	}	 


///////////////////////////////metodos de modulo////////////////////////////////////////////////////////////////	

	public function index()
	{
		redirect('home/open');	
	}

	public function view()
	{
		$this->data_view['_HEADER_TITLE'] = 'Mis Tickets';
		$this->data_view['_message_error'] = $this->session->flashdata('error');
		$this->data_view['_message_sucessfully'] = $this->session->flashdata('sucessfully');
		
		//inicializacion
		$this->load->library('pagination');
		$this->load->helper('sort');
		$this->load->helper('string');		
		$this->load->model('home_model');
		
		//variables del buscador	
		if ($this->input->post('search_post')){
			
		$search = $this->input->post('search');				
			$this->session->set_userdata('search', $search);
		} 		

		$this->data_view['search_value'] = $this->session->userdata('search');			
		
		$post_search = $this->input->post('search');
		$search_post = $this->input->post('search_post');
		$session_search = $this->session->userdata('search');


		//variables del ordenador
		$sort = $this->session->userdata('userSort');
		$direction = $this->session->userdata('userDirection');
		$perPage = $this->session->userdata('userCount');		

		if(!$perPage)
		{
			$perPage = 6;
			$this->session->set_userdata('userCount', $perPage);
		}			

		if(!$sort)
		{
			$sort = 'm1.fecha_creacion';
			$this->session->set_userdata('userSort', $sort);
		}

		if(!$direction)
		{
			$direction = 'desc';
			$this->session->set_userdata('userDirection', $direction);
		}


		$this->data_view['sort'] = $sort;
		$this->data_view['direction'] = $direction;
		$this->data_view['perPage'] = $perPage;				

		//configuracion del paginador
		$config['base_url'] = base_url().index_page().'/home/view/pagina';
		$config['total_rows'] = $this->home_model->getNumHome();
		$config['per_page'] = $perPage;	
		$config['uri_segment'] = 4;	
		
		$config['num_links'] = 1;
		$config['next_link'] = '<div class="page-right"></div>';
		$config['last_link'] = '<div class="page-far-right"></div>';
		$config['prev_link'] = '<div class="page-left"></div>';
		$config['first_link'] = '<div class="page-far-left"></div>';
		$config['num_tag_open'] = '<div id="page-info">';
		$config['num_tag_close'] = '</div>';
		$config['cur_tag_open'] = '<div id="page-info"><strong>';
		$config['cur_tag_close'] = '</strong></div>';		
		
		$this->pagination->initialize($config);		

		$this->data_view['users'] = $this->home_model->getAllHome($sort, $direction, $perPage, $this->uri->segment(4));	

		$this->data_view['pagination'] = $this->pagination->create_links();
		$this->data_view['pagina'] = $this->uri->segment(4);
		$this->data_view['numberPagina'] = $this->uri->segment(4) + 1;

		
		$this->load->view('home', $this->data_view);
	}
	
	
		public function sort()
	{
		if($this->input->post('sort'))	{
			$sort = $this->input->post('sort');
			$this->session->set_userdata('userSort', $sort);
		}		

		if($this->input->post('direction'))	{
			$direction = $this->input->post('direction');
			$this->session->set_userdata('userDirection', $direction);
		}
		
		redirect('home/view');
	}
	
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	

 

	
		public function open()
	{
		$this->data_view['_HEADER_TITLE'] = 'Mis tickets';
		$this->load->view('home', $this->data_view);
	}
	
		public function close()
	{
		$this->data_view['_HEADER_TITLE'] = 'Mis tickets';
		$this->load->view('home', $this->data_view);
	}
	
		public function add()
	{
		$this->data_view['_HEADER_TITLE'] = 'Mis tickets';
		$this->load->view('addTicket', $this->data_view);
	}
	
		public function detail()
	{
		$this->data_view['_HEADER_TITLE'] = 'Mis tickets';
		$this->load->view('homeDetail', $this->data_view);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/home.php */